package com.tuanzi.loan.business.service.templateConf.impl;

import com.tuanzi.loan.business.entity.templateConf.LoanApiActivityEntity;
import com.tuanzi.loan.business.repository.templateConf.ActivityRepository;
import com.tuanzi.loan.business.service.templateConf.ActivityService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.templateConf.ActivityRequest;
import com.tuanzi.loan.vo.response.templateConf.ActivityResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class ActivityServiceImpl extends CommonServiceImpl<LoanApiActivityEntity, Long> implements ActivityService {

	@Autowired
	private ActivityRepository activityRepository;

	@Override
	protected JpaRepository<LoanApiActivityEntity, Long> getRepository() {
		return activityRepository;
	}

	@Override
	public Page<ActivityResponse> list(PageSearcher<ActivityRequest> pageSearcher) {
		return activityRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public boolean offLine(Long id, Short status) {
		return activityRepository.updateStatus(id, status) > 0;
	}

}
